package com.slipper.system.role.front;

import com.slipper.common.bo.Result;
import com.slipper.system.role.service.RoleService;

import javax.annotation.Resource;
import org.springframework.web.bind.annotation.RestController;

import com.slipper.common.util.ResultUtil;
import com.slipper.system.api.role.bo.RoleBO;
import com.slipper.system.api.role.service.IRoleSv;

import java.util.List;

@RestController
public class RoleSv implements IRoleSv {
    @Resource
    private RoleService roleService;
    
    @Override
    public Result<RoleBO> queryBy(RoleBO bo){
        return ResultUtil.successResult(roleService.queryBy(bo));
    }
    
    @Override
    public Result<List<RoleBO>> queryPage(RoleBO bo){
        return ResultUtil.successResult(roleService.queryPage(bo));
    }
    
    @Override
    public Result<?> save(RoleBO bo){
        return ResultUtil.saveResult(roleService.save(bo));
    }
    
    @Override
    public Result<?> delete(RoleBO bo) {
        if (bo.getIds() != null) {
            for (String id : bo.getIds()) {
                if (this.roleService.isUse(id)) {
                    return ResultUtil.failureResult("此角色已经使用，不允许删除！");
                }
            }
        }
        return ResultUtil.deleteResult(roleService.delete(bo));
    }

    @Override
    public Result<Boolean> isSuperAdmin(String employeeId) {
        return ResultUtil.successResult(this.roleService.isSuperAdmin(employeeId));
    }

    @Override
    public Result<List<RoleBO>> queryList(RoleBO bo) {
        return ResultUtil.successResult(roleService.queryList(bo));
    }

    @Override
    public Result<List<String>> queryPower(RoleBO bo) {
        return ResultUtil.successResult(this.roleService.queryPower(bo));
    }

    @Override
    public Result<?> savePower(RoleBO bo) {
        return ResultUtil.saveResult(roleService.savePower(bo));
    }
}
